#if !USE_CONSOLE
#include "src/interface/rayTestPanel.h"

#include <iostream>

RayTestPanel::RayTestPanel(QWidget* _parent) : QWidget(_parent){
    originX = -1;
    originY = -1;
    originZ = -1;
    directionX = 0;
    directionY = 0;
    directionZ = 0;



    QLabel *originXLabel = new QLabel(tr("X:"));

    QDoubleSpinBox *originXDoubleSpinBox = new QDoubleSpinBox();
    originXDoubleSpinBox->setRange(-50.0, 50.0);
    originXDoubleSpinBox->setSingleStep(1.0);
    originXDoubleSpinBox->setValue(originX);
    connect(originXDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeOriginX(double)));


    QLabel *originYLabel = new QLabel(tr("Y:"));

    QDoubleSpinBox *originYDoubleSpinBox = new QDoubleSpinBox();
    originYDoubleSpinBox->setRange(-50.0, 50.0);
    originYDoubleSpinBox->setSingleStep(1.0);
    originYDoubleSpinBox->setValue(originY);
    connect(originYDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeOriginY(double)));


    QLabel *originZLabel = new QLabel(tr("Z:"));

    QDoubleSpinBox *originZDoubleSpinBox = new QDoubleSpinBox();
    originZDoubleSpinBox->setRange(-50.0, 50.0);
    originZDoubleSpinBox->setSingleStep(1.0);
    originZDoubleSpinBox->setValue(originZ);
    connect(originZDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeOriginZ(double)));


    QHBoxLayout *originLayout = new QHBoxLayout;
    originLayout->addWidget(originXLabel);
    originLayout->addWidget(originXDoubleSpinBox);
    originLayout->addStretch(1);
    originLayout->addWidget(originYLabel);
    originLayout->addWidget(originYDoubleSpinBox);
    originLayout->addStretch(1);
    originLayout->addWidget(originZLabel);
    originLayout->addWidget(originZDoubleSpinBox);
    originLayout->addStretch(1);

    QGroupBox *originGroupBox = new QGroupBox(QString::fromUtf8("Origem (ponto)"));
    originGroupBox->setLayout(originLayout);




    QLabel *directionXLabel = new QLabel(tr("X:"));

    QDoubleSpinBox *directionXDoubleSpinBox = new QDoubleSpinBox();
    directionXDoubleSpinBox->setRange(-50.0, 50.0);
    directionXDoubleSpinBox->setSingleStep(1.0);
    directionXDoubleSpinBox->setValue(directionX);
    connect(directionXDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeDirectionX(double)));


    QLabel *directionYLabel = new QLabel(tr("Y:"));

    QDoubleSpinBox *directionYDoubleSpinBox = new QDoubleSpinBox();
    directionYDoubleSpinBox->setRange(-50.0, 50.0);
    directionYDoubleSpinBox->setSingleStep(1.0);
    directionYDoubleSpinBox->setValue(directionY);
    connect(directionYDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeDirectionY(double)));


    QLabel *directionZLabel = new QLabel(tr("Z:"));

    QDoubleSpinBox *directionZDoubleSpinBox = new QDoubleSpinBox();
    directionZDoubleSpinBox->setRange(-50.0, 50.0);
    directionZDoubleSpinBox->setSingleStep(1.0);
    directionZDoubleSpinBox->setValue(directionZ);
    connect(directionZDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeDirectionZ(double)));


    QHBoxLayout *directionLayout = new QHBoxLayout;
    directionLayout->addWidget(directionXLabel);
    directionLayout->addWidget(directionXDoubleSpinBox);
    directionLayout->addStretch(1);
    directionLayout->addWidget(directionYLabel);
    directionLayout->addWidget(directionYDoubleSpinBox);
    directionLayout->addStretch(1);
    directionLayout->addWidget(directionZLabel);
    directionLayout->addWidget(directionZDoubleSpinBox);
    directionLayout->addStretch(1);

    QGroupBox *directionGroupBox = new QGroupBox(QString::fromUtf8("Direção (ponto)"));
    directionGroupBox->setLayout(directionLayout);

    QPushButton *testButton = new QPushButton("Testar", this);
    connect(testButton, SIGNAL(clicked()), this, SLOT(accept()));

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(originGroupBox);
    mainLayout->addWidget(directionGroupBox);
    mainLayout->addWidget(testButton);
    mainLayout->addStretch(1);

    setLayout(mainLayout);

}

RayTestPanel::~RayTestPanel(){
}

void RayTestPanel::accept(){
    if((originX == directionX) && (originY == directionY) && (originZ == directionZ)){
        QMessageBox::information(this, QString::fromUtf8("Direção invalida"), QString::fromUtf8("Escolha um ponto que seja diferente da origem para existir uma direção."));
        return;
    }

    Vector3D origin(originX, originY, originZ);
    Vector3D direction = Vector3D(directionX, directionY, directionZ) - origin;

    emit test(Ray(origin, direction.normalize()));
}

void RayTestPanel::changeOriginX(double _x){
    originX = _x;
}

void RayTestPanel::changeOriginY(double _y){
    originY = _y;
}

void RayTestPanel::changeOriginZ(double _z){
    originZ = _z;
}

void RayTestPanel::changeDirectionX(double _x){
    directionX = _x;
}

void RayTestPanel::changeDirectionY(double _y){
    directionY = _y;
}

void RayTestPanel::changeDirectionZ(double _z){
    directionZ = _z;
}
#endif //!USE_CONSOLE
